package edu.gyc.objecthomework;/*
 * GetInput.java
 *
 * Created on February 15, 2007, 4:09 PM
 *
 * Solution to Exercise 5
 */

/**
 *
 * @author charleshoot
 */

import java.util.Scanner;

public class GetInput {
    
    private int minimum;
    private int maximum;
    private String prompt;
    
    
    
    
    public void initialize(int min, int max, String p) {
        minimum = min;
        maximum = max;
        prompt = p;
        
        
        if(minimum > maximum) {
            minimum = max;
            maximum = min;
            System.out.println("The minimum was greater than the maximum " +
                    "so set minimum to the smaller value and maximum to the larger.");
        }
    }
    
    public int getValue(){
        System.out.println(prompt);
        Scanner reader = new Scanner(System.in);
        
        int data = reader.nextInt();
        while(data > maximum  || data < minimum){
            System.out.println("Sorry, the data value must be in the range of " +
                    minimum + " to " + maximum);
            System.out.println();
            System.out.println(prompt);
            data = reader.nextInt();
        }
        
        return data;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        GetInput integerReader1 = new GetInput();
        GetInput integerReader2 = new GetInput();
        GetInput integerReader3 = new GetInput();
        integerReader1.initialize(10, 0, "Give me a value from 10 to 0.");
        integerReader2.initialize(0, 10, "Give me a value from 0 to 10.");
        integerReader3.initialize(-150, 0, "What is a freezing temperature?");
        
        int data;
        
        data = integerReader1.getValue();
        System.out.println("We got the value " + data + "\n");
        
        data = integerReader2.getValue();
        System.out.println("We got the value " + data + "\n");
        
        data = integerReader3.getValue();
        System.out.println("We got the value " + data + "\n");
        
        
    }
    
}

